<template>
	<div>
		<div>
			<div style="margin-bottom: 10px;display: inline-block;width: 100%;">
				<el-button style="margin-left:15px;" size="mini" type="primary" icon="document" @click="handleChange55">
					刷新</el-button>
			</div>
			<el-button style="margin-left:15px;" size="mini" type="primary" icon="document" @click="handleChange">
				测试按钮</el-button>

		</div>
		<div>
			<div id="container" style="width:95%;height:80vh;margin-left: 2.5%;"></div>
		</div>
	</div>
</template>

<script>
	import {
		jsonp
	} from 'vue-jsonp'
	import {
		provinceAndCityData,
		regionData,
		provinceAndCityDataPlus,
		regionDataPlus,
		CodeToText,
		TextToCode
	} from 'element-china-area-data'
	var geocoder, map, markersArray,infoWindow = [];
	export default {
		data() {
			return {
				limit: 10,
				page: 1,
				shopName1: '',
				shopId: '',
				shopName: '',
				openTime: '',
				closeTime: '',
				detailedAddress: '',
				shopLng: '',
				shopLat: '',
				percentage1: 0, //进度条
				img: [], //任务轮播图
				// img: '',
				classn: '',
				value: [],
				parentId: 0,
				parentIdnum: '',

				tableDataLoading: false,
				dialogFormVisible1: false,
				dialogFormVisible2: false,
				dialogFormVisible3: false,
				dialogFormVisible: false,
				typeDatas: {},
				typeDatas1: {},
				titles: '添加',
				// 地图相关
				longitude: '', //经度
				latitude: '', //维度
				loadingMap: true,
				BMap: '',
				map: '',
				geoc: '',
				keyword: '',
				showMap: false,
				pointLngLat: '',
				center: {
					lng: 115.892151,
					lat: 28.676493
				},
				lng: 115.892151,
				lat: 28.676493,
				storeAddress: [],
				storeAddre: '请选择城市',
				form: {
					province: '',
					city: '', //市
					district: '', //区
				},
				dialogImageUrl: [],
				dialogVisible: false,
				erweimaImg: '',
				activeName: 'first',
				shopTypeName: '',
				shopTypId: '',
				titles1: '',
				labels: [], //标签集合
				bq: '', //输入的标签名
				province: '',
				city: '', //市
				district: '', //区
				options: regionData,
				shopCover: '',
				shopTypenum: [],
				typeDatas2: [],
				shopType: '',
				geometries: [],
				center: '',
				map: '',
				lists: [],
				index1: 0,
				tableData: {},
				hospitalId: '',
				ordersNo: '',
				userName: '',
				type: '',
				typeNum: [{
						value: '',
						label: '全部'
					},
					{
						value: 1,
						label: '陪诊订单'
					},
					{
						value: 2,
						label: '陪护订单'
					},
				],
			}
		},
		methods: {
			handleSizeChange(val) {
				this.limit = val
				this.dataSelectoder()
			},
			handleCurrentChange(val) {
				this.page = val
				this.dataSelectoder()
			},
			//定位获得当前位置信息
			getMyLocation() {
				var geolocation = new qq.maps.Geolocation("ZBABZ-ZWECU-UQTVV-4LYDR-COK3F-5SF75", "来点小收入");
				geolocation.getIpLocation(this.showPosition, this.showErr);
			},
			showPosition(position) {
				this.setMap();
			},
			showErr(e) {
				this.getMyLocation(); //定位失败再请求定位，测试使用
			},
			//位置信息在地图上展示
			setMap() {
				var center = new TMap.LatLng(this.latitude, this.longitude);
				map = []
				infoWindow = []
				// 初始化地图
				map = new TMap.Map('container', {
					zoom: 13, // 设置地图缩放级别
					pitch: 30,
					center: center, // 设置地图中心点坐标
					// mapStyleId: "style1", //个性化样式
					baseMap: {
						type: 'vector',
						features: ['base', 'building3d'], // 隐藏矢量文字
					},
				});
				console.log('this.geometries', this.geometries)
				// marker文字在图片内
				
				var marker = new TMap.MultiMarker({
					map: map,
					styles: {
						default: new TMap.MarkerStyle({
							width: 66, // 宽度
							height: 66, // 高度
							anchor: {
								x: 46,
								y: 46
							}, // 锚点位置
							src: 'https://mapapi.qq.com/web/lbs/visualizationApi/demo/img/circle.png', // 标注点图片url或base64地址
							color: '#fff', // 标注点文本颜色
							size: 14, // 标注点文本文字大小
							offset: {
								x: 0,
								y: 16
							}, // 标注点文本文字基于direction方位的偏移属性
						}),
					},
					geometries: this.geometries
				});
				
				//初始化infoWindow
				console.log('this.geometries',this.geometries.length)
				// infoWindow.clear();
				for(var i in this.geometries){
					infoWindow = new TMap.InfoWindow({
					    map: map,
					    position: new TMap.LatLng(this.geometries[i].datas.hospitalLat, this.geometries[i].datas.hospitalLng),
					    offset: { x: 0, y: -32 } //设置信息窗相对position偏移像素
					});
					// infoWindow.clears();//关闭信息窗
					console.log('``',infoWindow,this.geometries[i].datas.hospitalLat,'······',this.geometries[i].datas.hospitalLng)
					
					infoWindow.setContent('待接单数量：'+this.geometries[i].datas.ordersCount);//设置信息窗内容
					infoWindow.close();
					infoWindow.open();//初始信息窗开启
					// infoWindow.close(); //关闭信息窗
				}
				marker.on("click", function (evt) {
				    window.location.href = "/orderCenter?hospitalId=" + evt.geometry.datas.hospitalId;
				})

			},
			// 地图定位
			select() {
				console.log(this.detailedAddress)
				// this.address = this.province+ this.city+this.district+this.address
				var addr = this.province + this.city + this.district + this.address
				let that = this
				jsonp('https://apis.map.qq.com/ws/geocoder/v1/?address==' + addr +
					'&key=ZBABZ-ZWECU-UQTVV-4LYDR-COK3F-5SF75&get_poi=1&output=jsonp', {
						myCustomUrlParam: 'veryNice'
					}).then(response => {
					// handle success
					console.log('response', response)
					that.longitude = response.result.location.lng; // 经度
					that.latitude = response.result.location.lat; // 纬度
					// that.address = response.result.title
					that.setMap()
				}).catch(error => {
					// handle error
				}).then(() => {
					// always executed
				});
			},
			phoneSelect() {
				this.select()
			},
			onprogress1(event, file, fileList) {
				console.log('详情图上传进度', parseInt(event.percent))
				this.percentage1 = parseInt(event.percent)
			},
			// 获取省市区
			handleChange55(value) {
				this.dataSelect()
			},

			dataSelect() {
				this.$http({
					url: this.$http.adornUrl('admin/hospital/getHospitalOrderCount'),
					method: 'get',
					params: this.$http.adornParams({})
				}).then(({
					data
				}) => {
					console.log(data)
					var arr = []
					var arr1 = []
					if (data.data.length > 0) {

						for (var i in data.data) {
							if (data.data[i].hospitalLat && data.data[i].hospitalLng) {
								var obj = {}
								obj.position = new TMap.LatLng(data.data[i].hospitalLat, data.data[i].hospitalLng)
								obj.datas = data.data[i]
								obj.img = data.data[i].icon
								obj.content = data.data[i].hospitalName
								// obj['position'] = new TMap.LatLng(data.data.records[i].hospitalLat, data.data
								// 	.records[i].hospitalLng)
								// obj['datas'] = data.data.records[i]
								// obj['img'] = data.data.records[i].icon
								// obj['content'] = data.data.records[i].hospitalName
								// arr.push(new TMap.LatLng(data.data.records[i].hospitalLat, data.data.records[i]
								// 	.hospitalLng))
								arr.push(obj)
								arr1.push(obj)
							}

						}
						this.longitude = data.data[0].hospitalLng
						this.latitude = data.data[0].hospitalLat
						this.geometries = arr
						this.lists = arr1
						this.setMap();

					} else {
						this.$message({
							message: '暂无数据',
							type: 'warning',
							duration: 1500,
							onClose: () => {}
						})
					}

				})
			},
			// 重置
			cleans() {
				this.province = ''
				this.city = ''
				this.district = ''
				this.storeAddress = []
				this.storeAddre = '请选择城市'
				this.dataSelect()
			},
			updates(index) {
				this.$router.push({
					path: '/userDetail',
					query: {
						userId: this.lists[index].userId
					}
				})
			},
			// select选择事件
			animeDat(state) {
				this.page = 1
				this.dataSelectoder()
			},
			cleansDet() {
				this.page = 1
				this.type = ''
				this.userName = ''
				this.ordersNo = ''
				this.dataSelectoder()
			},
			// 获取医院订单
			dataSelectoder() {
				this.$http({
					url: this.$http.adornUrl('orders/queryOrders'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.limit,
						'type': this.type,
						'name': this.userName,
						'status': '',
						'ordersNo': this.ordersNo,
						'startTime': '',
						'endTime': '',
						'hospitalId': this.hospitalId
					})
				}).then(({
					data
				}) => {
					this.tableDataLoading = false
					let returnData = data.data;
					this.tableData = returnData

				})
			},
			handleChange(){
				this.$router.push({
					path: '/shifuScheduling',
				})
			},
		},
		created() {

		},
		mounted() {
			// this.setMap();
			// this.getMyLocation()
			this.dataSelect()

		}
	}
</script>

<style>
	.imgs {
		position: relative;
		border-radius: 6px;
		width: 148px;
		height: 148px;
		margin-right: 10px;
		display: inline-block;
	}

	.dels {
		position: absolute;
		top: 0;
		left: 0;
		display: none;
	}

	.dels .el-icon-delete {
		line-height: 148px;
		padding-left: 58px;
		font-size: 25px;
		color: #fff;
	}

	.imgs:hover .dels {
		width: 100%;
		height: 100%;
		background: #000;
		display: block;
		opacity: 0.5;
	}

	.bqList {
		padding: 4px 14px;
		margin: 4px;
		border: 1px solid #efefef;
		font-size: 12px;
		color: #999;
		border-radius: 4px;
		margin-right: 15px;
	}

	.delss {
		display: none;
		position: relative;
	}

	.delss .el-icon-delete {
		position: absolute;
		top: 0;
	}

	.bqList:hover .delss {
		display: initial;
		opacity: 0.5;

	}

	.tj {
		padding: 6px !important;
		margin: 4px;
		font-size: 12px;
		border: 1px solid #ccc;
		border-radius: 4px;
	}

	.csssprite {
		width: 100% !important;
		height: 100% !important;
		border-radius: 50% !important;
		min-width: 100% !important;
		max-width: 100% !important;
		min-height: 100% !important;
		max-height: 100% !important;
		border: 3px solid red !important;
	}
</style>
